package com.isunland.managesystem.ui;

import android.os.Bundle;
import android.view.View;
import com.google.gson.Gson;
import com.isunland.managesystem.adapter.AppointementOrderAdapter;
import com.isunland.managesystem.base.Base;
import com.isunland.managesystem.base.BaseListFragment;
import com.isunland.managesystem.entity.BookOrderInfo;
import com.isunland.managesystem.entity.BookOrderInfoListOriginal;
import com.isunland.managesystem.utils.MyUtils;
import com.isunland.managesystem.utils.ToastUtil;
import java.util.ArrayList;

/**
 * 对象功能: 预约下单
 * 开发公司: 北京信普达系统工程有限公司
 * 开发人员: wangyanan
 * 创建时间: 2017/1/3 14:20
 */

public abstract class BaseOrderListFragment extends BaseListFragment {

  public ArrayList<BookOrderInfo> mList;
  public AppointementOrderAdapter mAdapter;

  /**
   * Mandatory empty constructor for the fragment manager to instantiate the
   * fragment (e.g. upon screen orientation changes).
   */
  public BaseOrderListFragment() {
  }

  @Override public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mList = new ArrayList<>();
    mAdapter = new AppointementOrderAdapter(mActivity, mList);
  }

  @Override public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    int padding = MyUtils.dip2px(getActivity().getApplicationContext(), 16);
    //noinspection deprecation
    //mListview.setDivider(new ColorDrawable(getResources().getColor(android.R.color.transparent)));
    //mListview.setDividerHeight(padding);
    //mListview.setPadding(0, 0, 0, padding);
    setListAdapter(mAdapter);
  }

  @Override public void resolveResponse(String json) {
    //json = MyUtils.readAssetsFile(mActivity, "testAppointmentOrder.json");
    BookOrderInfoListOriginal result = new Gson().fromJson(json, BookOrderInfoListOriginal.class);
    if (result.getResult() == Base.SUCCESS && result.getRows() != null) {
      //获取列表成功
      mList.clear();
      mList.addAll(result.getRows());
      mAdapter.notifyDataSetChanged();
    } else {
      ToastUtil.show("获取列表失败");
    }
  }
}
